# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python


class Recipe(recipe.Recipe):
    name = 'cairo'
    version = '1.14.8'
    stype = SourceType.TARBALL
    url = 'http://cairographics.org/releases/cairo-1.14.8.tar.xz'
    # either LGPLv2.1 or MPLv1.1
    licenses = [License.LGPLv2_1]
    autoreconf = True
    autoreconf_sh = 'NOCONFIGURE=1 ./autogen.sh'
    deps = ['glib', 'libpng', 'zlib', 'pixman', 'fontconfig', 'freetype']
    patches = ['cairo/0001-Fix-compilation-with-Android-s-bionic-libc.patch',
               'cairo/0001-Disable-building-of-the-tests.patch',
               ]

    files_libs = ['libcairo', 'libcairo-gobject', 'libcairo-script-interpreter']
    files_devel = [
        'lib/pkgconfig/cairo-fc.pc',
        'lib/pkgconfig/cairo.pc',
        'lib/pkgconfig/cairo-ps.pc',
        'lib/pkgconfig/cairo-ft.pc',
        'lib/pkgconfig/cairo-pdf.pc',
        'lib/pkgconfig/cairo-svg.pc',
        'lib/pkgconfig/cairo-gobject.pc',
        'lib/pkgconfig/cairo-png.pc',
        'include/cairo',
        ]
    platform_files_devel = {
        Platform.WINDOWS: [ 'lib/pkgconfig/cairo-win32-font.pc',
                            'lib/pkgconfig/cairo-win32.pc'],
        Platform.DARWIN: ['lib/pkgconfig/cairo-quartz-font.pc',
                         'lib/pkgconfig/cairo-quartz-image.pc',
                         'lib/pkgconfig/cairo-quartz.pc']
    }

    # Skipping because it requires a display and documented as randomly failing
    make_check = None

    def prepare(self):
        # extra flags needed for gcc 4.9
        if self.config.target_distro == Distro.ARCH:
            self.append_env['CFLAGS'] = " -fno-lto "
            self.append_env['CXXFLAGS'] = " -fno-lto "
            self.append_env['CPPFLAGS'] = " -fno-lto "

        if self.config.variants.x11:
            self.files_devel += ['lib/pkgconfig/cairo-xlib-xrender.pc',
                                 'lib/pkgconfig/cairo-xlib.pc']
        else:
            self.configure_options += '--without-x '
        if self.config.target_platform == Platform.DARWIN:
            self.configure_options += ' --enable-quartz-font --enable-quartz-image'
